package jwj8508.momo;

import java.util.Scanner;

public class MovieService {

	char[] a = new char[10];
	Scanner sc = new Scanner(System.in);
	int k;
	
	public void mainMenu() {
		for (int i = 0; i < 10; i++) {
			a[i] = 'O';			
		}
		while(true) {
			System.out.println("극장 예약 시스템");		
			System.out.println("--------------");
			System.out.println("1. 예매");
			System.out.println("2. 환불");
			System.out.println("3. 종료");
			System.out.println("--------------");
			System.out.println("메뉴를 선택하세요");
		
			switch(sc.nextInt()) {
			case 1 : this.reserveMovie(); break;
			case 2 : this.refundMovie(); break;
			case 3 : System.exit(0);
			default : System.out.println("1-3의 숫자를 입력하세요.");			
			}
		}
	}
	
	public void reserveMovie() {		
		
		System.out.println("=== 예매 ===");
//		for (int i = 0; i < 10; i++) {
//			a[i] = 'O';			
//		}
		this.dpReserveState();		
		this.selectMenu();
		
//		while(true) {
			switch(k) {
				case 0 :
					System.out.println("종료됩니다.");
					System.exit(0);
				case 1 : a[0] = 'X'; break;
				case 2 : a[1] = 'X'; break;
				case 3 : a[2] = 'X'; break;
				case 4 : a[3] = 'X'; break;
				case 5 : a[4] = 'X'; break;
				case 6 : a[5] = 'X'; break;
				case 7 : a[6] = 'X'; break;
				case 8 : a[7] = 'X'; break;
				case 9 : a[8] = 'X'; break;
				case 10 : a[9] = 'X'; break;			
			}
			this.dpReserveState();
//			this.selectMenu();
			
//		}
		
	} // reserveMovie
	
	public void dpReserveState() {
		System.out.println("현재 예약 상태는 다음과 같습니다.");
		System.out.println("--------------------------------------------------------------");
		for (int i = 1; i <= 10; i++) {
			System.out.print(i + "\t");
		}
		System.out.println("\n------------------------------------------------------------");
		
		for (int i = 0; i < 10; i++) {
			System.out.print(a[i] + "\t");
		}
		System.out.println("\n------------------------------------------------------------");
	}

	public void selectMenu() {
		System.out.println("\n좌석을 선택하세요 [ 0 : 종료 ]");		
		k = sc.nextInt();
	}

	public void refundMovie() {			
		System.out.println("=== 환불 ===");
		this.dpReserveState();	
		this.selectMenu();
//		while (true) {
			if (a[k-1] == 'X') {
				switch(k) {
				case 0 :
					System.out.println("종료됩니다.");
					System.exit(0);
				case 1 : a[0] = 'O'; break;
				case 2 : a[1] = 'O'; break;
				case 3 : a[2] = 'O'; break;
				case 4 : a[3] = 'O'; break;
				case 5 : a[4] = 'O'; break;
				case 6 : a[5] = 'O'; break;
				case 7 : a[6] = 'O'; break;
				case 8 : a[7] = 'O'; break;
				case 9 : a[8] = 'O'; break;
				case 10 : a[9] = 'O'; break;			
				}
			} else if (a[k-1] == 'O'){
				System.out.println("예약된 좌석이 아닙니다.");
				this.dpReserveState();
				this.selectMenu();
			}
			this.dpReserveState();
//			this.selectMenu();			
//		}
		
	}	
}
